$(document).ready(function(){
	//setBackground();
	$(window).resize(function(){
		setBackground();
		if($(window).width() < 1027){
			$("#background-img").width(1027);
			$("#surprised .slide-01 img").width(1027);
		}else{
			$("#background-img").width($(window).width());
		$("#surprised .slide-01 img").width($(window).width());	
		}
		
		//$(".float-div").css(".")
		
	});
	changeBackground();
	setBackground();
	//鼠标移入移出导航坚挺
	$(".nav").delegate("a","mouseenter",function(e){
		$(e.target).prev().css("display","inline-block");
		$(e.target).next().css("display","inline-block");
	});
	$(".nav").delegate("a","mouseleave",function(e){
		$(e.target).prev().css("display","none");
		$(e.target).next().css("display","none");
	});
	$(".weixin-img").mouseenter(function(e){
		$(".code-for-weixin").show();
	});
	$(".weixin-img").mouseleave(function(e){
		$(".code-for-weixin").hide();
	});
	var canMoveMouseFlag = true;
	$(".for-left-nav").mouseenter(function(e){
		if(canMoveMouseFlag){
			canMoveMouseFlag = false;
			$(".nav-top").animate({left: '266px'}, "slow");
			$(".nav-bottom").animate({left: '266px'}, "slow",function(){
				canMoveMouseFlag = true;
			});
		}
		$(".menu a").css("background","url(res/menu2.png) no-repeat");
		$(".menu a").css("background-position","right center");
		$(".level-pager").css("display","none");
	});
	$(".left-nav").mouseleave(function(e){
		if(canMoveMouseFlag){
			canMoveMouseFlag = false;
			$(".nav-top").animate({left: '158px'}, "slow");
			$(".nav-bottom").animate({left: '-7px'}, "slow",function(){
				canMoveMouseFlag = true;
				$(".level-pager").css("display","block");
			});	
		}
		
		$(".menu a").css("background","url(res/menu.png) no-repeat");
		$(".menu a").css("background-position","right center");
	});
	//hover背景效果

	setHeight();

	$("#planning").hover(function(e){
		$("#planning").html("<p class = 'service-english'>PLANNING AND CREATIVE DESIGNS</p><p class='service-chinese'>策划及创意设计</p>");
	},function(e){
		$("#planning").html("");
	});
	$("#exhibition").hover(function(e){
		$("#exhibition").html("<p class = 'service-english'>COORDINATION OF EXHIBITION</p><p class='service-chinese'>展览展示实施</p>");
	},function(e){
		$("#exhibition").html("");
	});
	$("#coordination").hover(function(e){
		$("#coordination").html("<p class = 'service-english'>COMMERCIAL SPACE COORDINATION</p><p class='service-chinese'>商业空间实施</p>");
	},function(e){
		$("#coordination").html("");
	});
	$("#hall").hover(function(e){
		$("#hall").html("<p class = 'service-english'>THEME EXHIBITION HALL</p><p class='service-chinese'>展厅主题馆</p>");
	},function(e){
		$("#hall").html("");
	});
	$("#graphics").hover(function(e){
		$("#graphics").html("<p class = 'service-english'>GRAPHICS</p><p class='service-chinese'>平面设计</p>");
	},function(e){
		$("#graphics").html("");
	});
	$("#cehua").hover(function(e){
		$("#cehua").html("<p class = 'service-english'>EVENTS PLAN</p><p class='service-chinese'>活动策划</p>");
	},function(e){
		$("#cehua").html("");
	});
	$("#storage").hover(function(e){
		$("#storage").html("<p class = 'service-english'>LOGISTICS</p><p class = 'service-english'>STORAGE</p><p class='service-chinese'>物流仓储</p>");
	},function(e){
		$("#storage").html("");
	});
	$("#other").hover(function(e){
		$("#other").html("<p class = 'service-english'>OTHER SERVICES</p><p class='service-chinese'>其他服务</p>");
	},function(e){
		$("#other").html("");
	});
	var moveFlag = false;
	$("#service").click(function(e){
		if(moveFlag == false){
			$(".menu-service").fadeIn("fast");
			$(".service-intro").animate({left:"0px"},"slow",function(){
				moveFlag = true;
			});
			for(var i=0;i<9;i++){
				$(".service-content div:eq("+i+")").fadeOut("fast");
			}
			$(".service-text").fadeIn("slow");
		}else{
			$(".menu-service").fadeOut("fast");
			$(".service-intro").animate({left:"408px"},"slow",function(){
				moveFlag = false;
			});
			for(var i=0;i<9;i++){
				$(".service-content div:eq("+i+")").fadeIn("fast");
			}
			$(".service-text").fadeOut("fast");
		}
		
	});
	$(".menu-service").click(function(){
		$(".menu-service").fadeOut("fast");
		$(".service-intro").animate({left:"408px"},"slow",function(){
			moveFlag = false;
		});
		for(var i=0;i<9;i++){
			$(".service-content div:eq("+i+")").fadeIn("fast");
		}
		$(".service-text").fadeOut("fast");
	});
	var currentTab = 0;
	$(".service-content").delegate("a","click",function(){
		if($(this).attr("data-count")){
			currentTab = parseInt($(this).attr("data-count"));
			$(".service-intro").fadeOut("fast");
			for(var i=0;i<9;i++){
				$(".service-content div:eq("+i+")").fadeOut("fast");	
			}
			$(".service-"+parseInt($(this).attr("data-count"))).fadeIn("fast");
			$(".menu-back").fadeIn("fast");
			$(".to-left").fadeIn("fast");
			$(".to-right").fadeIn("fast");
		}
		if (currentTab == 1) {
			$(".to-left").css("display","none");
		}else if(currentTab == 8){
			$(".to-right").css("display","none");
		}
	});
	$(".service-content").delegate(".to-right","click",function(){
		$(".to-left").css("display","block");
		$(".service-"+currentTab).fadeOut("fast");
		$(".service-"+(currentTab+1)).fadeIn("fast");
		currentTab = currentTab +1;
		if(currentTab == 8){
			$(".to-right").css("display","none");
		}
	});
	$(".service-content").delegate(".to-left","click",function(){
		$(".to-right").css("display","block");
		$(".service-"+currentTab).fadeOut("fast");
		$(".service-"+(currentTab-1)).fadeIn("fast");
		currentTab = currentTab -1;
		if(currentTab == 1){
			$(".to-left").css("display","none");
		}
	});
	$(".menu-back").click(function(){
		$(".menu-back").fadeOut("fast");
		$(".to-left").fadeOut("fast");
		$(".to-right").fadeOut("fast");
		$(".hidden-service").fadeOut("fast");
		$(".service-intro").fadeIn("fast");
		for(var i=0;i<9;i++){
			$(".service-content div:eq("+i+")").fadeIn("fast");	
		}
		
	});

});
function setHeight(){
	$("#surprised .slide-01 img").css("height","949px");
	$(".background-img").css("height","949px");
	$(".background-img").css("background","url(res/background.png) repeat");
}

function changeBackground(){
	var picCount1 = 0;
	var picCount2 = 1;
	var i = 0;
	//标签计数
	var j = 1;
	var maxWidth = $(window).width();
	//alert(maxWidth);
	var timer = setInterval(changeBackImg,5);
	var listLeng = $("#surprised li").length;
	var flushFlag = false;
	function changeBackImg(){
		//alert(i);
		i = i + 1;
		if(i>maxWidth){
			if( picCount1 == listLeng){
				picCount1 = 0;
				setVis($("#surprised li:eq("+picCount1+")").find("img"));
				$(".name a:eq("+picCount1+")").css("display","none");
				$(".name-info p:eq("+picCount1+")").css("display","none");
				picCount1 = picCount1 + 1;
				
			}else{
				setVis($("#surprised li:eq("+picCount1+")").find("img"));
				$(".name a:eq("+picCount1+")").css("display","none");
				$(".name-info p:eq("+picCount1+")").css("display","none");
				picCount1 = picCount1 + 1;
			}
			currentImg = picCount1;
			if(picCount2 == listLeng){
				picCount2 = 0;
				setOpa($("#surprised li:eq("+picCount2+")").find("img"));
				$(".name a:eq("+picCount2+")").css("display","block");
				$(".name-info p:eq("+picCount2+")").css("display","block");
				picCount2 = picCount2 + 1;
			}else{
				setOpa($("#surprised li:eq("+picCount2+")").find("img"));
				$(".name a:eq("+picCount2+")").css("display","block");
				$(".name-info p:eq("+picCount2+")").css("display","block");
				picCount2 = picCount2 + 1;
			}
			i = 0;
			if( j == listLeng){
				j = 0;
				var nameWidthValue = parseInt($(".name1").css("width")) + (document.documentElement.clientWidth*0.45) - 54;
				$(".project").css("left",(nameWidthValue)+"px");
				j = j + 1;
			}else{
				var nameWidthValue = parseInt($(".name a:eq("+j+")").css("width")) + (document.documentElement.clientWidth*0.45) - 54;
				$(".project").css("left",(nameWidthValue)+"px");
				j = j + 1;
			}
		}
		$("#progress-bar").css("left",i+"px");
	}
}
//隐藏前一个元素
function setVis(imgDom){
	var opaImg = 1;
		var timerO = setInterval(runO,10);
		function runO(){
			imgDom.css("z-index","-30");
			opaImg = opaImg - 0.05;
			imgDom.css("opacity",opaImg);
			if(imgDom.css("opacity") == 0){
				clearInterval(timerO);
				imgDom.css("display","none");
			}
		}
}
//展示下一个元素
function setOpa(imgDom){
	var opaImg = 0;
		var timerO = setInterval(runO,10);
		function runO(){
			imgDom.css("z-index","-10");
			imgDom.css("display","block");
			opaImg = opaImg + 0.05;
			imgDom.css("opacity",opaImg);
			if(imgDom.css("opacity") == 1){
				clearInterval(timerO);
			}
		}
}
setBackground = function (){

	$("#surprised").width($(window).width());
	//$("#surprised").height($(window).height());
	$(".footer").height($(window).height()-381);
	if($(window).height() < 520){
		$(".footer").height(123);
	}
	
}